import { Form, Modal, Row, Col } from 'antd'
import React, { useEffect } from 'react'
import { formatDate, strToNum } from '@js/tool'
import moment from 'moment'
import Text from '@components/Text'
import FileList from '@components/FileList/Index'
import style from './Index.module.less'

const { Item, useForm } = Form

function initForm (data, formRef) {
  data.establish_datetime = strToNum(data.establish_datetime)
  if (data.establish_datetime) {
    data.establish_datetime = moment(data.establish_datetime * 1000)
  }
  formRef.setFieldsValue(data)
}

function Main ({ data, visible, hide, refreshFn }) {
  const [formRef] = useForm()
  useEffect(() => {
    if (formRef && data && visible) {
      initForm(data, formRef)
    }
  }, [formRef, data, visible])
  useEffect(() => {
    if (formRef && !visible) {
      formRef.resetFields()
    }
  }, [visible, formRef])
  return (
    <Modal title='分支机构详情' width={1000} open={visible} onCancel={hide} onOk={() => formRef.submit()} forceRender footer={null}>
      <Form form={formRef} className={style['detail-form']} labelCol={{ flex: '140px' }}>
        <Row gutter={24}>
          <Col span={12}>
            <Item noStyle name='id'><span /></Item>
            <Item name='name' label='机构名称' rules={[{ required: true, message: '机构名称不能为空' }]}>
              <Text />
            </Item>
            <Item label='机构简称' name='sname'>
              <Text />
            </Item>
            <Item label='机构英文名称' name='enname'>
              <Text />
            </Item>
            <Item label='机构英文简称' name='senname'>
              <Text />
            </Item>
            <Item label='机构代码' name='idno'>
              <Text />
            </Item>
            <Item name='principal' label='负责人/法定代表人'>
              <Text />
            </Item>
            <Item name='tel' label='联系电话'>
              <Text />
            </Item>
          </Col>
          <Col span={12}>
            <Item name='address' label='地址'>
              <Text />
            </Item>
            <Item name='establish_datetime' label='设立时间'>
              <Text format={v => v ? formatDate(v) : '无'} />
            </Item>
            <Item name='staff_num' label='工作人员数量'>
              <Text />
            </Item>
            <Item name='arbitrator_num' label='仲裁员数量'>
              <Text />
            </Item>
            <Item name='remark' label='备注'>
              <Text />
            </Item>
            <Item name='file' label='附件'>
              <FileList />
            </Item>
          </Col>
        </Row>
      </Form>
    </Modal>
  )
}

export default Main
